//
// Carl Beyer   cbeyer1
// Data Structures
// Programming Assignment 2
// myVector.h
// 9/15/09
//
// This is an implementation of a better
// vector class with bounds checks
//

#ifndef MYVECTOR_H
#define MYVECTOR_H

#include <vector>
#include <stdexcept>

template <typename T>
class Vector : public std::vector<T>
{
	public:
		Vector(int n = 0, const T& value = T());
		T& operator[](int i	);
};

// initialize using the vector constructor
template <typename T>
Vector<T>::Vector(int n, const T& value)
	: std::vector<T>(n, value)
{
}

template<typename T>
T& Vector<T>::operator[](int i)
{
	// throws an out_of_range exception when
	// trying to access a value outside the vector
	if(i < 0 || std::vector<T>::size() - 1 < i)
		throw std::out_of_range("in Vector<T>::operator[]");
	return std::vector<T>::at(i);
}

#endif

